var jwt = require('jsonwebtoken');
let str = 'hello world'//生命一个字符串给token添加标识
function createToken(obj){
    // // Date.now()获取当前的时间戳   等价于  new Date().getTime()
    obj.time = Date.now()
   return jwt.sign({
        data: obj
      }, str, { expiresIn: 60 * 60 });
}
function verifyToken(token){
    return new Promise((resolve,reject)=>{
        jwt.verify(token, str, function(err, decoded) {
            if(err){
                reject(err)
            }else{
                resolve(decoded)
            }
            
          });
    })
    
}
module.exports={
    createToken,
    verifyToken
}